import 'package:seedfour/generated/json/base/json_convert_content.dart';
import 'package:seedfour/app/models/user_account_entity.dart';

UserAccountEntity $UserAccountEntityFromJson(Map<String, dynamic> json) {
  final UserAccountEntity userAccountEntity = UserAccountEntity();
  final UserAccountBalance? balance = jsonConvert.convert<UserAccountBalance>(
      json['balance']);
  if (balance != null) {
    userAccountEntity.balance = balance;
  }
  final UserAccountMargin? margin = jsonConvert.convert<UserAccountMargin>(
      json['margin']);
  if (margin != null) {
    userAccountEntity.margin = margin;
  }
  return userAccountEntity;
}

Map<String, dynamic> $UserAccountEntityToJson(UserAccountEntity entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['balance'] = entity.balance?.toJson();
  data['margin'] = entity.margin?.toJson();
  return data;
}

extension UserAccountEntityExtension on UserAccountEntity {
  UserAccountEntity copyWith({
    UserAccountBalance? balance,
    UserAccountMargin? margin,
  }) {
    return UserAccountEntity()
      ..balance = balance ?? this.balance
      ..margin = margin ?? this.margin;
  }
}

UserAccountBalance $UserAccountBalanceFromJson(Map<String, dynamic> json) {
  final UserAccountBalance userAccountBalance = UserAccountBalance();
  final int? total = jsonConvert.convert<int>(json['total']);
  if (total != null) {
    userAccountBalance.total = total;
  }
  final String? sumAmount = jsonConvert.convert<String>(json['sumAmount']);
  if (sumAmount != null) {
    userAccountBalance.sumAmount = sumAmount;
  }
  final String? plusAmount = jsonConvert.convert<String>(json['plusAmount']);
  if (plusAmount != null) {
    userAccountBalance.plusAmount = plusAmount;
  }
  final String? minusAmount = jsonConvert.convert<String>(json['minusAmount']);
  if (minusAmount != null) {
    userAccountBalance.minusAmount = minusAmount;
  }
  final List<UserAccountBalanceData>? data = (json['data'] as List<dynamic>?)
      ?.map(
          (e) =>
      jsonConvert.convert<UserAccountBalanceData>(e) as UserAccountBalanceData)
      .toList();
  if (data != null) {
    userAccountBalance.data = data;
  }
  final List<UserAccountFundData>? allocData = (json['allocData'] as List<
      dynamic>?)
      ?.map(
          (e) =>
      jsonConvert.convert<UserAccountFundData>(e) as UserAccountFundData)
      .toList();
  if (allocData != null) {
    userAccountBalance.allocData = allocData;
  }
  return userAccountBalance;
}

Map<String, dynamic> $UserAccountBalanceToJson(UserAccountBalance entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['total'] = entity.total;
  data['sumAmount'] = entity.sumAmount;
  data['plusAmount'] = entity.plusAmount;
  data['minusAmount'] = entity.minusAmount;
  data['data'] = entity.data?.map((v) => v.toJson()).toList();
  data['allocData'] = entity.allocData?.map((v) => v.toJson()).toList();
  return data;
}

extension UserAccountBalanceExtension on UserAccountBalance {
  UserAccountBalance copyWith({
    int? total,
    String? sumAmount,
    String? plusAmount,
    String? minusAmount,
    List<UserAccountBalanceData>? data,
    List<UserAccountFundData>? allocData,
  }) {
    return UserAccountBalance()
      ..total = total ?? this.total
      ..sumAmount = sumAmount ?? this.sumAmount
      ..plusAmount = plusAmount ?? this.plusAmount
      ..minusAmount = minusAmount ?? this.minusAmount
      ..data = data ?? this.data
      ..allocData = allocData ?? this.allocData;
  }
}

UserAccountBalanceData $UserAccountBalanceDataFromJson(
    Map<String, dynamic> json) {
  final UserAccountBalanceData userAccountBalanceData = UserAccountBalanceData();
  final String? title = jsonConvert.convert<String>(json['title']);
  if (title != null) {
    userAccountBalanceData.title = title;
  }
  final int? createdAt = jsonConvert.convert<int>(json['createdAt']);
  if (createdAt != null) {
    userAccountBalanceData.createdAt = createdAt;
  }
  final String? amount = jsonConvert.convert<String>(json['amount']);
  if (amount != null) {
    userAccountBalanceData.amount = amount;
  }
  final int? changeSubtype = jsonConvert.convert<int>(json['changeSubtype']);
  if (changeSubtype != null) {
    userAccountBalanceData.changeSubtype = changeSubtype;
  }
  final String? afterBalance = jsonConvert.convert<String>(
      json['afterBalance']);
  if (afterBalance != null) {
    userAccountBalanceData.afterBalance = afterBalance;
  }
  final String? remark = jsonConvert.convert<String>(json['remark']);
  if (remark != null) {
    userAccountBalanceData.remark = remark;
  }
  return userAccountBalanceData;
}

Map<String, dynamic> $UserAccountBalanceDataToJson(
    UserAccountBalanceData entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['title'] = entity.title;
  data['createdAt'] = entity.createdAt;
  data['amount'] = entity.amount;
  data['changeSubtype'] = entity.changeSubtype;
  data['afterBalance'] = entity.afterBalance;
  data['remark'] = entity.remark;
  return data;
}

extension UserAccountBalanceDataExtension on UserAccountBalanceData {
  UserAccountBalanceData copyWith({
    String? title,
    int? createdAt,
    String? amount,
    int? changeSubtype,
    String? afterBalance,
    String? remark,
  }) {
    return UserAccountBalanceData()
      ..title = title ?? this.title
      ..createdAt = createdAt ?? this.createdAt
      ..amount = amount ?? this.amount
      ..changeSubtype = changeSubtype ?? this.changeSubtype
      ..afterBalance = afterBalance ?? this.afterBalance
      ..remark = remark ?? this.remark;
  }
}

UserAccountFundData $UserAccountFundDataFromJson(Map<String, dynamic> json) {
  final UserAccountFundData userAccountFundData = UserAccountFundData();
  final String? uid = jsonConvert.convert<String>(json['uid']);
  if (uid != null) {
    userAccountFundData.uid = uid;
  }
  final String? amount = jsonConvert.convert<String>(json['amount']);
  if (amount != null) {
    userAccountFundData.amount = amount;
  }
  final String? name = jsonConvert.convert<String>(json['name']);
  if (name != null) {
    userAccountFundData.name = name;
  }
  final String? mobile = jsonConvert.convert<String>(json['mobile']);
  if (mobile != null) {
    userAccountFundData.mobile = mobile;
  }
  return userAccountFundData;
}

Map<String, dynamic> $UserAccountFundDataToJson(UserAccountFundData entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['uid'] = entity.uid;
  data['amount'] = entity.amount;
  data['name'] = entity.name;
  data['mobile'] = entity.mobile;
  return data;
}

extension UserAccountFundDataExtension on UserAccountFundData {
  UserAccountFundData copyWith({
    String? uid,
    String? amount,
    String? name,
    String? mobile,
  }) {
    return UserAccountFundData()
      ..uid = uid ?? this.uid
      ..amount = amount ?? this.amount
      ..name = name ?? this.name
      ..mobile = mobile ?? this.mobile;
  }
}

UserAccountMargin $UserAccountMarginFromJson(Map<String, dynamic> json) {
  final UserAccountMargin userAccountMargin = UserAccountMargin();
  final int? total = jsonConvert.convert<int>(json['total']);
  if (total != null) {
    userAccountMargin.total = total;
  }
  final String? sumAmount = jsonConvert.convert<String>(json['sumAmount']);
  if (sumAmount != null) {
    userAccountMargin.sumAmount = sumAmount;
  }
  final String? plusAmount = jsonConvert.convert<String>(json['plusAmount']);
  if (plusAmount != null) {
    userAccountMargin.plusAmount = plusAmount;
  }
  final String? minusAmount = jsonConvert.convert<String>(json['minusAmount']);
  if (minusAmount != null) {
    userAccountMargin.minusAmount = minusAmount;
  }
  final List<UserAccountMarginData>? data = (json['data'] as List<dynamic>?)
      ?.map(
          (e) =>
      jsonConvert.convert<UserAccountMarginData>(e) as UserAccountMarginData)
      .toList();
  if (data != null) {
    userAccountMargin.data = data;
  }
  return userAccountMargin;
}

Map<String, dynamic> $UserAccountMarginToJson(UserAccountMargin entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['total'] = entity.total;
  data['sumAmount'] = entity.sumAmount;
  data['plusAmount'] = entity.plusAmount;
  data['minusAmount'] = entity.minusAmount;
  data['data'] = entity.data?.map((v) => v.toJson()).toList();
  return data;
}

extension UserAccountMarginExtension on UserAccountMargin {
  UserAccountMargin copyWith({
    int? total,
    String? sumAmount,
    String? plusAmount,
    String? minusAmount,
    List<UserAccountMarginData>? data,
  }) {
    return UserAccountMargin()
      ..total = total ?? this.total
      ..sumAmount = sumAmount ?? this.sumAmount
      ..plusAmount = plusAmount ?? this.plusAmount
      ..minusAmount = minusAmount ?? this.minusAmount
      ..data = data ?? this.data;
  }
}

UserAccountMarginData $UserAccountMarginDataFromJson(
    Map<String, dynamic> json) {
  final UserAccountMarginData userAccountMarginData = UserAccountMarginData();
  final int? createdAt = jsonConvert.convert<int>(json['createdAt']);
  if (createdAt != null) {
    userAccountMarginData.createdAt = createdAt;
  }
  final String? amount = jsonConvert.convert<String>(json['amount']);
  if (amount != null) {
    userAccountMarginData.amount = amount;
  }
  final int? orderStatus = jsonConvert.convert<int>(json['orderStatus']);
  if (orderStatus != null) {
    userAccountMarginData.orderStatus = orderStatus;
  }
  final int? marginDate = jsonConvert.convert<int>(json['marginDate']);
  if (marginDate != null) {
    userAccountMarginData.marginDate = marginDate;
  }
  final String? remark = jsonConvert.convert<String>(json['remark']);
  if (remark != null) {
    userAccountMarginData.remark = remark;
  }
  return userAccountMarginData;
}

Map<String, dynamic> $UserAccountMarginDataToJson(
    UserAccountMarginData entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['createdAt'] = entity.createdAt;
  data['amount'] = entity.amount;
  data['orderStatus'] = entity.orderStatus;
  data['marginDate'] = entity.marginDate;
  data['remark'] = entity.remark;
  return data;
}

extension UserAccountMarginDataExtension on UserAccountMarginData {
  UserAccountMarginData copyWith({
    int? createdAt,
    String? amount,
    int? orderStatus,
    int? marginDate,
    String? remark,
  }) {
    return UserAccountMarginData()
      ..createdAt = createdAt ?? this.createdAt
      ..amount = amount ?? this.amount
      ..orderStatus = orderStatus ?? this.orderStatus
      ..marginDate = marginDate ?? this.marginDate
      ..remark = remark ?? this.remark;
  }
}